package com.lzm.ydpt.mvp.presenterimpl;

import com.byt.framlib.basemvp.BasePresenter;
import com.byt.framlib.basemvp.basebean.BaseResponseBean;
import com.byt.framlib.basemvp.boby.FormBodys;
import com.byt.framlib.basemvp.exception.ApiException;
import com.byt.framlib.basemvp.listener.OnLoadingErrorListener;
import com.byt.framlib.basemvp.listener.OnLoadingProgressListener;
import com.google.gson.JsonObject;
import com.lzm.ydpt.entity.mall.MallOrderBean;
import com.lzm.ydpt.entity.riding.OrderBean;
import com.lzm.ydpt.module.mall.activity.MallOrderDetailsActivity;
import com.lzm.ydpt.mvp.api.ProgressSubscriber;
import com.lzm.ydpt.mvp.contract.MallOrderDetailsContract;
import com.lzm.ydpt.mvp.modelimpl.MallOrderDetailsModelImpl;

import java.util.Map;

/**
 * 类名称：XhXnOrderDetailsPresenterImpl
 * 类描述：代理实现
 */
public class MallOrderDetailsPresenterImpl extends BasePresenter implements MallOrderDetailsContract.Presenter {

    private MallOrderDetailsContract.View mView;
    private MallOrderDetailsContract.Model mModel;

    public MallOrderDetailsPresenterImpl(MallOrderDetailsActivity context) {
        super(context);
        this.mView = context;
        this.mModel = new MallOrderDetailsModelImpl();
    }

    @Override
    public void onOrderDetails(FormBodys formBodys) {
        mManager.http(mModel.onOrderDetails(formBodys), getLifecycleProvider(), new ProgressSubscriber<>(mContext, new OnLoadingProgressListener<MallOrderBean>() {
            @Override
            public void onLoadingResult(BaseResponseBean<MallOrderBean> entity) {
                mView.onOrderDetails(entity.getData());
            }
        }, new OnLoadingErrorListener() {
            @Override
            public void onError(ApiException e, String method) {
                mView.showErrorView(e.getDisplayMessage());
            }

            @Override
            public void onErrorResult(BaseResponseBean entity, String method) {
                mView.showErrorView(entity.getMessage());
            }
        }, "onOrderDetails"));
    }

    @Override
    public void onCancalOrder(FormBodys formBodys) {
        mManager.http(mModel.onCancalOrder(formBodys), getLifecycleProvider(), new ProgressSubscriber<>(mContext, new OnLoadingProgressListener<Object>() {
            @Override
            public void onLoadingResult(BaseResponseBean<Object> entity) {
                mView.onCancalOrder(entity.getMessage());
            }
        }, new OnLoadingErrorListener() {
            @Override
            public void onError(ApiException e, String method) {
                mView.showMessage(e.getDisplayMessage(), method);
            }

            @Override
            public void onErrorResult(BaseResponseBean entity, String method) {
                mView.showMessage(entity.getMessage(), method);
            }
        }, "onCancalOrder"));
    }

    @Override
    public void onDeteleOrder(FormBodys formBodys) {
        mManager.http(mModel.onDeteleOrder(formBodys), getLifecycleProvider(), new ProgressSubscriber<>(mContext, new OnLoadingProgressListener<Object>() {
            @Override
            public void onLoadingResult(BaseResponseBean<Object> entity) {
                mView.onDeteleOrder(entity.getMessage());
            }
        }, new OnLoadingErrorListener() {
            @Override
            public void onError(ApiException e, String method) {
                mView.showMessage(e.getDisplayMessage(), method);
            }

            @Override
            public void onErrorResult(BaseResponseBean entity, String method) {
                mView.showMessage(entity.getMessage(), method);
            }
        }, "onDeteleOrder"));
    }

    @Override
    public void onReceiptOrder(FormBodys formBodys) {
        mManager.http(mModel.onReceiptOrder(formBodys), getLifecycleProvider(), new ProgressSubscriber<>(mContext, new OnLoadingProgressListener<Object>() {
            @Override
            public void onLoadingResult(BaseResponseBean<Object> entity) {
                mView.onReceiptOrder(entity.getMessage());
            }
        }, new OnLoadingErrorListener() {
            @Override
            public void onError(ApiException e, String method) {
                mView.showMessage(e.getDisplayMessage(), method);
            }

            @Override
            public void onErrorResult(BaseResponseBean entity, String method) {
                mView.showMessage(entity.getMessage(), method);
            }
        }, "onReceiptOrder"));
    }
}